# -*- coding:utf8 -*-
#!/usr/bin/env python

import nltk, re
from django.utils.encoding import smart_str, smart_unicode

from django.core.management.base import BaseCommand, CommandError
from feedsaver.saver.models import News,NewsArchive


def loop(self,ns):

	stopwords = nltk.corpus.stopwords.words('portuguese') 
	
	#for n in ns
	text = ns[0].text
	text = text.lower()

	#Removing punctuation
	text = text.replace(',','')
	text = text.replace('.',' ')
	text = text.replace("'",'')
	text = text.replace('"','')
	text = text.replace('!','')
	text = text.replace(';','')
	text = text.replace(':','')
	text = text.replace('(','')
	text = text.replace(')','')

	text = text.split(' ')
	#text = ''.join(text)

	#Removing stopwords
	for word in text:
		if word not in stopwords:
			word = smart_str(word, encoding='utf-8', strings_only=False, errors='strict')
			self.stdout.write(word)
			self.stdout.write(' ')
	
	return


def mcw(self):
	#Most Common Words
	#Faz um loop por todos os textos de um assunto e retorna um array com as principais palavras
	
	

	#Brasil
	ns = NewsArchive.objects.filter(subject='br')



	return 

class Command(BaseCommand):
    args = 'no args'
    help = 'Extract info from CPR'
    
    def handle(self, *args, **options):
        mcw(self)

        return